﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace Kokomo
{
	public class TypedUIElementCollection<TElement> : ICollection<TElement>
		where TElement : UIElement
	{
		protected TypedUIElementCollection(
			UIElement visualParent,
			FrameworkElement logicalParent
			)
		{
			this._innerCollection = new UIElementCollection(visualParent, logicalParent);
		}

		private UIElementCollection _innerCollection;

		public void Add(TElement item)
		{
			this._innerCollection.Add(item);
		}

		public void Clear()
		{
			this._innerCollection.Clear();
		}

		public bool Contains(TElement item)
		{
			return this._innerCollection.Contains(item);
		}

		public void CopyTo(TElement[] array, int arrayIndex)
		{
			this._innerCollection.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get { return this._innerCollection.Count; }
		}

		public bool IsReadOnly
		{
			get { return false; }
		}

		public bool Remove(TElement item)
		{
			bool contains = this._innerCollection.Contains(item);
			this._innerCollection.Remove(item);

			return contains;
		}

		public IEnumerator<TElement> GetEnumerator()
		{
			return this._innerCollection.OfType<TElement>().GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return this._innerCollection.GetEnumerator();
		}
	}
}
